/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.fd.manager.impl;

import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;

import com.xy.biz.fd.domain.po.DocumentReleaseOftenUsePO;
import com.xy.tool.context.UserContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xy.biz.fd.domain.bo.DocumentReleaseOftenUseBO;
import com.xy.biz.fd.domain.query.DocumentReleaseOftenUseQuery;
import com.xy.biz.fd.domain.converter.DocumentReleaseOftenUseConverter;
import com.xy.biz.fd.manager.DocumentReleaseOftenUseManager;
import com.xy.biz.fd.dao.DocumentReleaseOftenUseDao;

/**
 *
 *
 * @author zgy
 * @date 2021-6-15
 */
@Service
public class DocumentReleaseOftenUseManagerImpl implements DocumentReleaseOftenUseManager {

    @Autowired
    private DocumentReleaseOftenUseDao documentReleaseOftenUseDao;

    @Override
    public int saveDocumentReleaseOftenUse(DocumentReleaseOftenUseBO documentReleaseOftenUseBO) {
        return documentReleaseOftenUseDao.saveDocumentReleaseOftenUse(DocumentReleaseOftenUseConverter.toPO(documentReleaseOftenUseBO));
    }

    @Override
    public int saveAllDocumentReleaseOftenUse(Collection<DocumentReleaseOftenUseBO> collection) {
        return documentReleaseOftenUseDao.saveAllDocumentReleaseOftenUse(DocumentReleaseOftenUseConverter.toPO(collection));
    }

    @Override
    public int updateDocumentReleaseOftenUse(DocumentReleaseOftenUseBO documentReleaseOftenUseBO) {
        return documentReleaseOftenUseDao.updateDocumentReleaseOftenUse(DocumentReleaseOftenUseConverter.toPO(documentReleaseOftenUseBO));
    }

    @Override
    public int increment(DocumentReleaseOftenUseBO documentReleaseOftenUseBO) {
        int rows;
        //无则新建，有则自增
        DocumentReleaseOftenUseBO documentReleaseOftenUseByBO = getDocumentReleaseOftenUseByBO(documentReleaseOftenUseBO);
        if (documentReleaseOftenUseByBO == null) {
            LocalDateTime now = LocalDateTime.now();
            documentReleaseOftenUseBO.setSequence(1);
            documentReleaseOftenUseBO.setTenantId(UserContextHolder.getTenantId());
            documentReleaseOftenUseBO.setCreateTime(now);
            documentReleaseOftenUseBO.setUpdateTime(now);
            documentReleaseOftenUseBO.setDeleteFlag(false);
            rows = saveDocumentReleaseOftenUse(documentReleaseOftenUseBO);
        } else {
            documentReleaseOftenUseByBO.increment();
            rows = documentReleaseOftenUseDao.increment(DocumentReleaseOftenUseConverter.toPO(documentReleaseOftenUseByBO));
        }
        return rows;
    }

    @Override
    public int deleteDocumentReleaseOftenUse(Long documentReleaseOftenUseId) {
        return documentReleaseOftenUseDao.deleteDocumentReleaseOftenUse(documentReleaseOftenUseId);
    }

    @Override
    public DocumentReleaseOftenUseBO getDocumentReleaseOftenUse(Long documentReleaseOftenUseId) {
        return DocumentReleaseOftenUseConverter.fromPO(documentReleaseOftenUseDao.getDocumentReleaseOftenUse(documentReleaseOftenUseId));
    }

    @Override
    public DocumentReleaseOftenUseBO getDocumentReleaseOftenUseByBO(DocumentReleaseOftenUseBO documentReleaseOftenUseBO) {
        DocumentReleaseOftenUsePO documentReleaseOftenUsePO = DocumentReleaseOftenUseConverter.toPO(documentReleaseOftenUseBO);
        return DocumentReleaseOftenUseConverter.fromPO(documentReleaseOftenUseDao.getDocumentReleaseOftenUseByBO(documentReleaseOftenUsePO));
    }

    @Override
    public List<DocumentReleaseOftenUseBO> listDocumentReleaseOftenUseById(Collection<Long> collection) {
        return DocumentReleaseOftenUseConverter.fromPO(documentReleaseOftenUseDao.listDocumentReleaseOftenUseById(collection));
    }

    @Override
    public List<DocumentReleaseOftenUseBO> listDocumentReleaseOftenUse(DocumentReleaseOftenUseQuery query) {
        return DocumentReleaseOftenUseConverter.fromPO(documentReleaseOftenUseDao.listDocumentReleaseOftenUse(query));
    }

    @Override
    public int countDocumentReleaseOftenUse(DocumentReleaseOftenUseQuery query) {
        return documentReleaseOftenUseDao.countDocumentReleaseOftenUse(query);
    }

}
